{extend name="/fool" /}
{block name="css"}
<link rel="stylesheet" href="/css/admin/order_two.css">
<style>
    #page{
        position: relative;
        display: inline-block;
        left:30%;
        margin-left:-50px;
        padding:50px 0;
    }
</style>
{/block}
{block name="menu_content"}
<div id="one">
    <form class="layui-form" action="" method="post">
        <ul>
            <li>
                <div>
                    搜索机台编号：
                    <div class="layui-input-inline">
                        <input type="text" name="batterybaid" autocomplete="off" id="jtnum" class="layui-input" placeholder="机台编号">
                    </div>
                    <button type="button" class="layui-btn ss">搜索</button>
                    <div class="layui-input-inline" id="ss">
                        <input type="text" name="batterybaid" autocomplete="off" class="layui-input" disabled style="background:#e7e7e7;">
                    </div>
                    <button type="button" class="layui-btn" id="fp">分配给服务中心</button>
                </div>

            </li>
            <li>
                <div class="layui-input-inline">
                    <input type="text" name="batterybaid" autocomplete="off" class="layui-input" placeholder="机台编号">
                </div>
                <button type="Submit" class="layui-btn">筛选</button>
            </li>
        </ul>
    </form>
</div>
<div>
    <table>
        <tr>
            <th>添加时间</th>
            <th>操作人</th>
            <th>机台编号</th>
            <th class="last">操作</th>
        </tr>
        {if isset($list)}
        {foreach $list as $v}
        <tr class="list">
            <td>{$v.id}</td>
            <td>{$v.name}</td>
            <td>{$v.batterybaid}</td>
            <td>
                <button sid="{$v.id}" type="button" class="view layui-btn layui-bg-blue">详情</button>
                <button sid="{$v.id}" type="button" class="delete layui-btn">删除</button>
            </td>
        </tr>
        {/foreach}
        {/if}
    </table>
    <div id="page">
    </div>
</div>
<script>
    $("#fp").click(function(){
        var val = $("#ss").find('input').val();
        var sid = $("#ss").find('input').attr('sid');
        if(val.length>1){
            $.post("{:url('fp')}",{'id':"{$id}",'sid':sid,},function(res){
                history.go(0);
            },'json')
        }
    })
    $(".ss").click(function(){
        var num = $("#jtnum").val();
        if(num.length>1){
            $.post("{:url('ss')}",{batterybaid:num},function(res){
                console.log(res);
                $("#ss").find('input').val(res.list.name);
                $("#ss").find('input').attr('sid',res.list.id);
            },'json')
        }else{
            $("#ss").find('input').val('');
        }
    })
    $(".add").click(function(){
        location.href = "{:url('add')}"
    })
    $(".view").click(function(){
        var id = $(this).attr('sid');
        location.href = "{:url('indexs')}" + '?id=' + id;
    })
    $(".delete").click(function(){
        var id = $(this).attr('sid');
        location.href = "{:url('delete')}" + '?id=' + id;
    })
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#test1'
            ,type: 'month'
            ,range: '至'
            ,format: 'yyyy-MM'
        });
    });
    layui.use('laypage', function(){
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
            elem: 'page'
            ,count: "{$count}"
            ,curr:"{$curl}"
            ,last:"{$groups}"
            ,limit:"{$limit}"
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            ,jump: function(obj,first){
                console.log(obj)
                if(!first){
                    var url = "{:url('index',['id'=>5,'index'=>0])}" + '&page=' + obj.curr + '&limit=' + obj.limit + '&curr=' + obj.curr;
                    location.href = url;
                }
            }
        });
    });
</script>
{/block}